package net.frankish.tools.progress;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class FrankishProgressBar extends JPanel{

	private static final long serialVersionUID = 1L;
	private JProgressBar progressBar;


	public FrankishProgressBar(){
		progressBar = new JProgressBar();

		setBackground(Color.WHITE);
		progressBar.setPreferredSize(new Dimension(230,20));
		progressBar.setMaximumSize(new Dimension(230,20));
		setLayout(new BorderLayout());
		add(progressBar,BorderLayout.CENTER);
	}

	public void startUndefined(String text){
		progressBar.setStringPainted(text!=null);
		progressBar.setString(text);
		progressBar.setIndeterminate(true);
	}
	public void startProgress(String text){
		progressBar.setStringPainted(text!=null);
		progressBar.setIndeterminate(false);
		progressBar.setValue(0);
		progressBar.setMaximum(100);
		progressBar.setString(text);
	}
	public void progress(int step, String text){
		progressBar.setStringPainted(text!=null);
		progressBar.setValue(progressBar.getValue()+step);
		if(text != null)
			progressBar.setString(text);
	}

	public void stopProgress(String text){
		progressBar.setStringPainted(text!=null);
		progressBar.setValue(progressBar.getMaximum());
		if(text != null)
			progressBar.setString(text);
		else
			progressBar.setString("Finished");
		try {
			Thread.sleep(700);
		} catch (InterruptedException e) {
		}
	}
}
